Alibaba Arthas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

文档地址[https://alibaba.github.io/arthas/advanced-use.html]


$ curl -O https://alibaba.github.io/arthas/arthas-boot.jar

#Demo进程是第2个,则输入2,再输入回车/enter。Arthas会attach到目标进程上,并输出日志
$ java -jar arthas-boot.jar
* [1]: 35542
[2]: 71560 arthas-demo.jar

[INFO] Try to attach process 71560
[INFO] Attach process 71560 success.
[INFO] arthas-client connect 127.0.0.1 3658
,---. ,------. ,--------.,--. ,--. ,---. ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
| .-. || '--'.' | | | .--. || .-. |`. `-.
| | | || |\ \ | | | | | || | | |.-' |
`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'

wiki: https://alibaba.github.io/arthas
version: 3.0.5.20181127201536
pid: 71560
time: 2018-11-28 19:16:24


#当前系统的实时数据面板
$ dashboard

#arthas-demo进程的Main Class
$ thread 1 | grep 'main('
at demo.MathGame.main(MathGame.java:17)

#反编译python
$ jad demo.MathGame

#通过watch命令来查看demo.MathGame#primeFactors函数的返回值
$ watch demo.MathGame primeFactors returnObj


#返回当前的工作目录,和linux命令类似
$ pwd
/data/alpha-market/jars

#查看当前会话的信息
$ session
Name Value
--------------------------------------------------
JAVA_PID 7276
SESSION_ID 8af7f372-0c5d-4d6a-972b-33840aa6d2fb

# 打印命令历史
$ history
1 dashboard
2 dashboard
3 thread 1 | grep 'main('
4 jad demo.MathGame
5 watch demo.MathGame primeFactors returnObj
6 jvm

#关闭 Arthas 服务端,所有 Arthas 客户端全部退出
$ stop


#查看当前 JVM 的线程堆栈信息
$ thread
Threads Total: 90, NEW: 0, RUNNABLE: 21, BLOCKED: 0, WAITING: 44, TIMED_WAITING: 25, TERMINATED: 0
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTED DAEMON
75 Thread-2 main 5 RUNNABLE 29 4:12 false false
1511 as-command-execute-daemon system 10 RUNNABLE 20 0:0 false true
82 SendDepth-pool-2 main 5 RUNNABLE 17 28:22 false false
79 Thread-4 main 5 TIMED_WAITING 14 12:20 false false
1456 task-56 main 5 TIMED_WAITING 4 0:1 false false
1453 task-53 main 5 TIMED_WAITING 3 0:1 false false
1454 task-54 main 5 TIMED_WAITING 3 0:1 false fal

#查看当前 JVM 的信息
$ jvm

#通过getstatic命令可以方便的查看类的静态属性
$ getstatic com.alpha.market.service.impl.QueryServiceImpl logger